<?php
namespace app\shop\controller;
use think\Controller;
use think\Request;
use think\Db;
use app\service\billService;
use app\service\lifeapiService;//生活号接口
use app\service\shopService;
use app\service\appletService;
use printing\printShop;

class Ali extends Controller{
	public function getuser(){
		$api = new lifeapiService();
		//获取当前用户支付宝ID
		$code = request()->get('auth_code');
		$oauthtoken = $api->oauthToken($code);
		if(property_exists($oauthtoken,'sub_msg')){
			return json(['info' => $oauthtoken->sub_msg]);
		}
		session('user_id',$oauthtoken->user_id);
        $url=session("url");
        $this->redirect($url);
        die;	
	}

	public function testnotice1(){
		//$address = 'C:\phpStudy\WWW\zaozao\public\shop\onlinealinotice\\'.date('YmdHis').rand(100000,999999).'.txt';
		$address = 'C:\phpStudy\WWW\zaozao\public\shop\onlinealinotice\20190722115541584414.txt';
        //file_put_contents($address,file_get_contents("php://input"),FILE_APPEND);//将数据读入文本
        parse_str(file_get_contents($address),$notice);//读取文本并变成数组
        if($notice['trade_status'] == 'TRADE_SUCCESS'){
        	$orderinfo=Db::table('zz_order_online')->where('out_order_no',$notice['out_trade_no'])->find();
        	$shopinfo= (new shopService())->shopIdInfo($orderinfo["shop_id"]);
            if($orderinfo["order_status"]=="0"){
	        	$data["order_id"]=$orderinfo["order_id"];
	    		$data["payment_type"]="1";//支付方式:支付宝
	    		$data['order_status'] = '1';
	            $data['pay_time'] = date('Y-m-d H:i:s');
				$data['pay_money'] = $notice['receipt_amount'];
				$data['give_point']=$notice['receipt_amount'];
				$res=Db::table("zz_order_online")->update($data);

				//更新房屋的积分
				Db::table('roominfo')->where('out_room_id',$orderinfo["out_room_id"])->setInc('point', $data['give_point']);
				$roominfo=Db::table('roominfo')->where('out_room_id',$orderinfo["out_room_id"])->find();
				//给用户推送信息
				$msg["title"]="尊敬的会员，你有一笔新的积分入账啦";
				$msg["user_id"]=$orderinfo["buyer_id"];
				$msg["url"]="";
				$msg["shop_name"]=$shopinfo["shop_name"];
				$msg["pay_money"]=$data['pay_money']."元";
				$msg["give_point"]=$data['give_point']."积分";
				$msg["point"]=$roominfo["point"]."积分";
				$msg["time"]=$notice['gmt_payment'];
				$msg["remark"]="";
				$api = new lifeapiService();
		        $result = $api->getPointMsg(json_encode($msg));

		        //给商家推送一条订单信息
		        $merchantmsg["title"]="您收到一条新的订单";
				$merchantmsg["user_id"]=$shopinfo["user_id"];//"2088102690661313";
				$merchantmsg["url"]="http://www.jfzhiwen.com/shop/merchant/orderListOnline";
				$merchantmsg["pay_time"]=date('Y-m-d H:i:s');
				$merchantmsg["order_type"]="番茄积分商城";
				$merchantmsg["buyer_nickname"]=$orderinfo["buyer_nickname"];
				$merchantmsg["order_msg"]="";
				$ordergoods=Db::table("zz_order_goods")->where("order_id",$orderinfo["order_id"])->select();
				foreach ($ordergoods as $key => $value) {
					$merchantmsg["order_msg"]=$merchantmsg["order_msg"]."   ".$ordergoods["goods_name"]."*".$ordergoods["num"];
				}
				$merchantmsg["remark"]="";

				$res=$api->ordermsgshop(json_encode($merchantmsg));
			}

			//打印
        	if($orderinfo["printing"]=="0"){
        		
        		$printdata["order_id"]=$orderinfo["order_id"];
        		$ordergoods=Db::table("zz_order_goods")->where("order_id",$orderinfo["order_id"])->select();
        		foreach ($ordergoods as $key => $value) {
        			$details[]= $value["goods_name"]."*". $value["num"];
        		}
        		$printing = (new printShop())->payonlineprinting($shopinfo["machine_code"],$orderinfo["community_name"],$orderinfo["receive_address"],$notice['trade_no'],"支付宝",$notice['receipt_amount'],$notice['gmt_payment'],$orderinfo['give_point'],$orderinfo['buyer_nickname'],$details,$orderinfo["receive_name"],$orderinfo["receive_phone"],$orderinfo["shop_name"]);
        		$printing1 = (new printShop())->payonlineprinting($shopinfo["machine_code"],$orderinfo["community_name"],$orderinfo["receive_address"],$notice['trade_no'],"支付宝",$notice['receipt_amount'],$notice['gmt_payment'],$orderinfo['give_point'],$orderinfo['buyer_nickname'],$details,$orderinfo["receive_name"],$orderinfo["receive_phone"],$orderinfo["shop_name"]);
        		var_dump($printing);
        		var_dump($printing1);
        		if($printing){
        			$printdata["printing"]="1";
        			$res=Db::table('zz_order_online')->update($printdata);
        		}
        	}

        	//转账
        	if($orderinfo["transfer_status"]=="0"){
        		$api = new lifeapiService();
				$transfer_data["out_biz_no"]=$notice['trade_no'];
				$transfer_data["payee_type"]="ALIPAY_USERID";
				$transfer_data["payee_account"]=$shopinfo["shop_account"]; //2088231771220793
				$money=$notice['receipt_amount']*(1-$shopinfo["shop_commission_rate"]);
				$money=(int)(ceil($money*100));
	    		$money=$money/100;
				$transfer_data["amount"]=$money;
				$transfer_data["payer_show_name"]=$orderinfo["buyer_logon_id"].$orderinfo["buyer_nickname"];
				$transfer_data["payee_real_name"]=$shopinfo["shop_account_name"];
				$transfer_data["remark"]="番茄会员消费";
				$result=$api->accountTransfer(json_encode($transfer_data));
				var_dump($result);
				//转账成功
				if($result->code=="10000"){
					//往转账记录插入一条记录
					$transfer_record["shop_id"]=$shopinfo["shop_id"];
					$transfer_record["shop_name"]=$shopinfo["shop_name"];
					$transfer_record["shop_account"]=$shopinfo["shop_account"];
					$transfer_record["shop_rate"]=$shopinfo["shop_commission_rate"];
					$transfer_record["transfer_money"]=$money;
					$transfer_record["pay_money"]=$notice['receipt_amount'];
					$transfer_record["out_order_no"]=$orderinfo['out_order_no'];
					$transfer_record["transaction_id"]=$orderinfo['transaction_id'];
					$transfer_record["logon_id"]=$orderinfo['buyer_logon_id'];
					$transfer_record["user_id"]=$orderinfo['buyer_id'];
					$transfer_record["user_name"]=$orderinfo['buyer_nickname'];
					$transfer_record["order_id"]=$orderinfo['order_id'];
					$re=Db::table('zz_order_online')->insert($transfer_record);

					$transfer["order_id"]=$order["order_id"];
					$transfer["transfer_status"]=1;
					Db::table('zz_order_online')->update($transfer);

				}
        	}
        }
	}
	//线上商城订单回调
	public function onlinenotice(){
		$address = 'C:\phpStudy\WWW\zaozao\public\shop\onlinealinotice\\'.date('YmdHis').rand(100000,999999).'.txt';
		//$address = 'C:\phpStudy\WWW\zaozao\public\shop\onlinealinotice\20190723121021725588.txt';
        file_put_contents($address,file_get_contents("php://input"),FILE_APPEND);//将数据读入文本
        parse_str(file_get_contents($address),$notice);//读取文本并变成数组
        if($notice['trade_status'] == 'TRADE_SUCCESS'){
        	$orderinfo=Db::table('zz_order_online')->where('out_order_no',$notice['out_trade_no'])->find();
        	$shopinfo= (new shopService())->shopIdInfo($orderinfo["shop_id"]);
            if($orderinfo["order_status"]=="0"){
	        	$data["order_id"]=$orderinfo["order_id"];
	    		$data["payment_type"]="1";//支付方式:支付宝
	    		$data['order_status'] = '1';
	            $data['pay_time'] = date('Y-m-d H:i:s');
				$data['pay_money'] = $notice['receipt_amount'];
				$data['give_point']=$notice['receipt_amount'];
				$res=Db::table("zz_order_online")->update($data);

				//更新房屋的积分
				Db::table('roominfo')->where('out_room_id',$orderinfo["out_room_id"])->setInc('point', $data['give_point']);
				$roominfo=Db::table('roominfo')->where('out_room_id',$orderinfo["out_room_id"])->find();
				//给用户推送信息
				$msg["title"]="尊敬的会员，你有一笔新的积分入账啦";
				$msg["user_id"]=$orderinfo["buyer_id"];
				$msg["url"]="";
				$msg["shop_name"]=$shopinfo["shop_name"];
				$msg["pay_money"]=$data['pay_money']."元";
				$msg["give_point"]=$data['give_point']."积分";
				$msg["point"]=$roominfo["point"]."积分";
				$msg["time"]=$notice['gmt_payment'];
				$msg["remark"]="";
				$api = new lifeapiService();
		        $result = $api->getPointMsg(json_encode($msg));

		        //给商家推送一条订单信息
		        $merchantmsg["title"]="您收到一条新的订单";
				$merchantmsg["user_id"]=$shopinfo["user_id"];//"2088102690661313";
				$merchantmsg["url"]="http://www.jfzhiwen.com/shop/merchant/orderListOnline";
				$merchantmsg["pay_time"]=date('Y-m-d H:i:s');
				$merchantmsg["order_type"]="番茄积分商城";
				$merchantmsg["buyer_nickname"]=$orderinfo["buyer_nickname"];
				$merchantmsg["order_msg"]="";
				$ordergoods=Db::table("zz_order_goods")->where("order_id",$orderinfo["order_id"])->select();
				foreach ($ordergoods as $key => $value) {
					$merchantmsg["order_msg"]=$merchantmsg["order_msg"]."   ".$ordergoods["goods_name"]."*".$ordergoods["num"];
				}
				$merchantmsg["remark"]="";

				$res=$api->ordermsgshop(json_encode($merchantmsg));
			}

			//打印
        	if($orderinfo["printing"]=="0"){
        		
        		$printdata["order_id"]=$orderinfo["order_id"];
        		$ordergoods=Db::table("zz_order_goods")->where("order_id",$orderinfo["order_id"])->select();
        		foreach ($ordergoods as $key => $value) {
        			$details[]= $value["goods_name"]."*". $value["num"];
        		}
        		$printing = (new printShop())->payonlineprinting($shopinfo["machine_code"],$orderinfo["community_name"],$orderinfo["receive_address"],$notice['trade_no'],"支付宝",$notice['receipt_amount'],$notice['gmt_payment'],$orderinfo['give_point'],$orderinfo['buyer_nickname'],$details,$orderinfo["receive_name"],$orderinfo["receive_phone"],$orderinfo["shop_name"]);
        		$printing1 = (new printShop())->payonlineprinting($shopinfo["machine_code"],$orderinfo["community_name"],$orderinfo["receive_address"],$notice['trade_no'],"支付宝",$notice['receipt_amount'],$notice['gmt_payment'],$orderinfo['give_point'],$orderinfo['buyer_nickname'],$details,$orderinfo["receive_name"],$orderinfo["receive_phone"],$orderinfo["shop_name"]);
        		var_dump($printing);
        		if($printing){
        			$printdata["printing"]="1";
        			$res=Db::table('zz_order_online')->update($printdata);
        		}
        	}

        	//转账
        	if($orderinfo["transfer_status"]=="0"){
        		$api = new lifeapiService();
				$transfer_data["out_biz_no"]=$notice['trade_no'];
				$transfer_data["payee_type"]="ALIPAY_USERID";
				$transfer_data["payee_account"]=$shopinfo["shop_account"]; //2088231771220793
				$money=$notice['receipt_amount']*(1-$shopinfo["shop_commission_rate"]);
				$money=(int)(ceil($money*100));
	    		$money=$money/100;
				$transfer_data["amount"]=$money;
				$transfer_data["payer_show_name"]=$orderinfo["buyer_logon_id"].$orderinfo["buyer_nickname"];
				$transfer_data["payee_real_name"]=$shopinfo["shop_account_name"];
				$transfer_data["remark"]="番茄会员消费";
				$result=$api->accountTransfer(json_encode($transfer_data));
				var_dump($result);
				//转账成功
				if($result->code=="10000"){
					//往转账记录插入一条记录
					$transfer_record["shop_id"]=$shopinfo["shop_id"];
					$transfer_record["shop_name"]=$shopinfo["shop_name"];
					$transfer_record["shop_account"]=$shopinfo["shop_account"];
					$transfer_record["shop_rate"]=$shopinfo["shop_commission_rate"];
					$transfer_record["transfer_money"]=$money;
					$transfer_record["pay_money"]=$notice['receipt_amount'];
					$transfer_record["out_order_no"]=$orderinfo['out_order_no'];
					$transfer_record["transaction_id"]=$orderinfo['transaction_id'];
					$transfer_record["logon_id"]=$orderinfo['buyer_logon_id'];
					$transfer_record["user_id"]=$orderinfo['buyer_id'];
					$transfer_record["user_name"]=$orderinfo['buyer_nickname'];
					$transfer_record["order_id"]=$orderinfo['order_id'];
					$re=Db::table('zz_order_online')->insert($transfer_record);

					$transfer["order_id"]=$order["order_id"];
					$transfer["transfer_status"]=1;
					Db::table('zz_order_online')->update($transfer);

				}
        	}
        }
	}


	//支付宝支付回调
	public function notice(){
		$address = 'C:\phpStudy\WWW\zaozao\public\shop\alinotice\\'.date('YmdHis').rand(100000,999999).'.txt';
		//$address = 'C:\phpStudy\WWW\zaozao\public\shop\alinotice\20190719202423943832.txt';
        file_put_contents($address,file_get_contents("php://input"),FILE_APPEND);//将数据读入文本
        parse_str(file_get_contents($address),$notice);//读取文本并变成数组
        if($notice['trade_status'] == 'TRADE_SUCCESS'){
        	$order = (new shopService())->tradeOrderInfo($notice['trade_no']);
        	$shopinfo= (new shopService())->shopIdInfo($order["shop_id"]);
        	//更改订单状态
        	if($order["order_status"]=="0"){
        		//
        		$data["order_id"]=$order["order_id"];
        		$data["pay_type"]="1";//支付方式
        		$data['order_status'] = '1';
                $data['pay_time'] = $notice['gmt_payment'];
				$data['pay_money'] = $notice['receipt_amount'];
				$data['give_point']=$notice['receipt_amount'];
				$res=(new shopService())->orderEdit($data);

				//更新房屋的积分
				Db::table('roominfo')->where('out_room_id',$order["out_room_id"])->setInc('point', $data['give_point']);
				$roominfo=Db::table('roominfo')->where('out_room_id',$order["out_room_id"])->find();

				$msg["title"]="尊敬的会员，你有一笔新的积分入账啦";
				$msg["user_id"]=$order["buyer_id"];
				$msg["url"]="";
				$msg["shop_name"]=$shopinfo["shop_name"];
				$msg["pay_money"]=$data['pay_money']."元";
				$msg["give_point"]=$data['give_point']."积分";
				$msg["point"]=$roominfo["point"]."积分";
				$msg["time"]=$notice['gmt_payment'];
				$msg["remark"]="";
				$api = new lifeapiService();
		        $result = $api->getPointMsg(json_encode($msg));
        	}
        	
        	//打印
        	if($order["printing"]=="0"){
        		
        		$printdata["order_id"]=$order["order_id"];
        		$printing = (new printShop())->payprinting($shopinfo["machine_code"],$order["community_name"],$order["room_address"],$notice['trade_no'],"支付宝",$notice['receipt_amount'],$notice['gmt_payment'],$order['give_point'],$order['user_name']);
        		if($printing){
        			$printdata["printing"]="1";
        			$res=(new shopService())->orderEdit($printdata);
        		}
        	}
        	
        	//转账
        	if($order["transfer_status"]=="0"){
        		$api = new lifeapiService();
				$transfer_data["out_biz_no"]=$notice['trade_no'];
				$transfer_data["payee_type"]="ALIPAY_USERID";
				$transfer_data["payee_account"]=$shopinfo["shop_account"]; //2088231771220793
				$money=$notice['receipt_amount']*(1-$shopinfo["shop_commission_rate"]);
				$money=(int)(ceil($money*100));
	    		$money=$money/100;
				$transfer_data["amount"]=$money;
				$transfer_data["payer_show_name"]=$order["logon_id"].$order["user_name"];
				$transfer_data["payee_real_name"]=$shopinfo["shop_account_name"];
				$transfer_data["remark"]="番茄会员消费";
				$result=$api->accountTransfer(json_encode($transfer_data));
				//转账成功
				if($result->code=="10000"){
					//往转账记录插入一条记录
					$transfer_record["shop_id"]=$shopinfo["shop_id"];
					$transfer_record["shop_name"]=$shopinfo["shop_name"];
					$transfer_record["shop_account"]=$shopinfo["shop_account"];
					$transfer_record["shop_rate"]=$shopinfo["shop_commission_rate"];
					$transfer_record["transfer_money"]=$money;
					$transfer_record["pay_money"]=$notice['receipt_amount'];
					$transfer_record["out_trade_no"]=$order['out_trade_no'];
					$transfer_record["order_no"]=$order['order_no'];
					$transfer_record["logon_id"]=$order['logon_id'];
					$transfer_record["user_id"]=$order['buyer_id'];
					$transfer_record["user_name"]=$order['user_name'];
					$re=(new shopService())->transferadd($transfer_record);

					$transfer["order_id"]=$order["order_id"];
					$transfer["transfer_status"]=1;
					(new shopService())->orderEdit($transfer);

				}
        	}
        }
	}

	

	//支付宝支付回调
	public function billnotice(){
		$address = 'C:\phpStudy\WWW\zaozao\public\shop\bill\alinotice\\'.date('YmdHis').rand(100000,999999).'.txt';
		//$address='C:\phpStudy\WWW\zaozao\public\shop\bill\alinotice\20190724222839787496.txt';
        file_put_contents($address,file_get_contents("php://input"),FILE_APPEND);//将数据读入文本
        parse_str(file_get_contents($address),$notice);//读取文本并变成数组
        if($notice['trade_status'] == 'TRADE_SUCCESS'){
        	//$order = (new shopService())->tradeOrderInfo($notice['trade_no']);
        	$billorder=Db::table('zz_bill_order')->where('trade_no',$notice['trade_no'])->find();
        	//更改订单状态
        	if($billorder["order_status"]=="0"){
        		//
        		$data["id"]=$billorder["id"];
        		$data["pay_type"]="1";//支付方式
        		$data['order_status'] = '1';
                $data['pay_time'] = $notice['gmt_payment'];
				$data['pay_money'] = $notice['receipt_amount'];
				$res=Db::table('zz_bill_order')->update($data);
				//如果订单使用积分，则更新房屋的积分
				if($billorder["point_status"]=="1"){
					if($billorder["point"]>0){
						Db::table('roominfo')->where('out_room_id',$billorder["out_room_id"])->setDec('point', $billorder["point"]);
					}
				}
        	}
        	//修改账单状态
        	$billid=unserialize($billorder["bill_id"]);
        	foreach ($billid as $key => $value) {
        		$billinfo=(new billService())->billIdinfo($value);
        		if($billinfo["status"]!="TRADE_SUCCESS"){
        			$info['pay_type'] = '支付宝';//付款类型
	                $info['trade_no'] = $notice['trade_no'];//支付宝交易号
	                $info['gmt_payment'] = $notice['gmt_payment'];//付款时间
	                $info['status'] = $notice['trade_status'];//付款状态
	                $info['id'] = $value;
	                 //修改数据
               		$billedit = (new billService())->billApiEdit($info);
        		} 
        		//删除已同步账单
        		if($billinfo["tongbu"]=="1"){
                    $res=(new appletService())->alibilldel($billinfo['id']);
                    if($res){
                    	 Db::table("bill")->where('id',$billinfo['id'])->update(["tongbu"=>"3"]);
                    }
                }  
                $detailed[] = '费用类型: '.$billinfo['cost_type'];
                $detailed[] = '账期: '.$billinfo['acct_period'];
                $detailed[] = '金额: '.$billinfo['bill_entry_amount']; 
        	}
        	
        	//判断是否转账
        	if(($billorder["point_status"]=="1")&&($billorder["point_money"]>0)){
        		if($billorder["transfer_status"]=="0"){
        			$property=(new shopService())->communityProperty($billorder["community_id"]);
	        		$api = new lifeapiService();
	        		$transfer_rate=0.0038;
					$transfer_data["out_biz_no"]=$notice['trade_no'];
					$transfer_data["payee_type"]="ALIPAY_USERID";
					$transfer_data["payee_account"]=$property["merchantpid"]; //2088231771220793
					$money=$billorder['point_money']*(1-$transfer_rate);
					$money=(int)(ceil($money*100));
		    		$money=$money/100;
					$transfer_data["amount"]=$money;
					$transfer_data["payer_show_name"]=$billorder["logon_id"].$billorder["user_name"];
					$transfer_data["payee_real_name"]=$property["name"];
					$transfer_data["remark"]="番茄会员消费";
					$result=$api->accountTransfer(json_encode($transfer_data));
					var_dump($result);
					//转账成功
					if($result->code=="10000"){
						$transfer["id"]=$billorder["id"];
						$transfer["transfer_status"]=1;
						Db::table('zz_bill_order')->update($transfer);


						//往物业转账记录插入一条记录
						$transfer_bill["community_id"]=$billorder["community_id"];
						$transfer_bill["community_name"]=$billorder["community_name"];
						$transfer_bill["property_account"]=$property["merchantpid"];
						$transfer_bill["property_name"]=$property["name"];
						$transfer_bill["transfer_money"]=$money;
						$transfer_bill["point_money"]=$billorder['point_money'];
						$transfer_bill["out_order_no"]=$billorder['out_order_no'];
						$transfer_bill["trade_no"]=$billorder['trade_no'];
						$transfer_bill["transfer_rate"]=$transfer_rate;
						Db::table("zz_transfer_bill")->insert($transfer_bill);

					}
	        	}
        	}
        	//打印
        	if($billorder["printing"]=="0"){
        		$printdata["id"]=$billorder["id"];
        		$communityinfo = (new billService())->communityMachine($billorder['community_id']);
        		$propertyinfo=(new billService())->propertyInfo($communityinfo["property_id"]);
        		//$machine_code="4004624379";
        		$machine_code=$communityinfo["machine_code"];
        		$printing = (new printShop())->billprinting($machine_code,$billorder["community_name"],$billorder["room_address"],$notice['trade_no'],"支付宝",$notice['receipt_amount'],$notice['gmt_payment'],$billorder["order_money"],$billorder["point_money"],$detailed,$propertyinfo["name"]);
        		var_dump($printing);
        		if($printing){
        			$printdata["printing"]="1";
        			Db::table("zz_bill_order")->update($printdata);
        		}
        	}
        	
        }
	}

	public function testnotice(){
		$address = 'C:\phpStudy\WWW\zaozao\public\shop\onlalinotice\20190712135140633605.txt';
        file_put_contents($address,file_get_contents("php://input"),FILE_APPEND);//将数据读入文本
        parse_str(file_get_contents($address),$notice);//读取文本并变成数组
        echo "<pre>";
        //var_dump($notice);
        //die;
        if($notice['trade_status'] == 'TRADE_SUCCESS'){
        	$order = (new shopService())->tradeOrderInfo($notice['trade_no']);
        	//更改订单状态
        	if($order["order_status"]=="0"){
        		//
        		$data["order_id"]=$order["order_id"];
        		$data["pay_type"]="1";//支付方式
        		$data['order_status'] = '1';
                $data['pay_time'] = $notice['gmt_payment'];
				$data['pay_money'] = $notice['receipt_amount'];
				$data['give_point']=$notice['receipt_amount'];
				$res=(new shopService())->orderEdit($data);

				//更新房屋的积分
				Db::table('roominfo')->where('out_room_id',$order["out_room_id"])->setInc('point', $data['give_point']);
        	}
        	$shopinfo= (new shopService())->shopIdInfo($order["shop_id"]);
        	//打印
        	if($order["printing"]=="0"){
        		
        		$printdata["order_id"]=$order["order_id"];
        		$printing = (new printShop())->payprinting($shopinfo["machine_code"],$order["community_name"],$order["room_address"],$notice['trade_no'],"支付宝",$notice['receipt_amount'],$notice['gmt_payment']);
        		var_dump($printing);
        		if($printing){
        			$printdata["printing"]="1";
        			$res=(new shopService())->orderEdit($printdata);
        		}
        	}
        	//转账
        	if($order["transfer_status"]=="0"){
        		$api = new lifeapiService();
				$transfer_data["out_biz_no"]=$notice['trade_no'];
				$transfer_data["payee_type"]="ALIPAY_USERID";
				$transfer_data["payee_account"]=$shopinfo["shop_account"]; //2088231771220793
				$money=$notice['receipt_amount']*(1-$shopinfo["shop_commission_rate"]);
				$money=ceil($money*100);
	    		$money=$money/100;
				$transfer_data["amount"]=$money;
				$transfer_data["payer_show_name"]=$order["logon_id"].$order["user_name"];
				$transfer_data["payee_real_name"]=$shopinfo["shop_account_name"];
				$transfer_data["remark"]="1";
				$result=$api->accountTransfer(json_encode($transfer_data));
				var_dump($result);
				//转账成功
				if($result->code=="10000"){
					//往转账记录插入一条记录
					$transfer_record["shop_id"]=$shopinfo["shop_id"];
					$transfer_record["shop_name"]=$shopinfo["shop_name"];
					$transfer_record["shop_account"]=$shopinfo["shop_account"];
					$transfer_record["shop_rate"]=$shopinfo["shop_commission_rate"];
					$transfer_record["transfer_money"]=$money;
					$transfer_record["pay_money"]=$notice['receipt_amount'];
					$transfer_record["out_trade_no"]=$order['out_trade_no'];
					$transfer_record["order_no"]=$order['order_no'];
					$transfer_record["logon_id"]=$order['logon_id'];
					$transfer_record["user_id"]=$order['buyer_id'];
					$transfer_record["user_name"]=$order['user_name'];
					$re=(new shopService())->transferadd($transfer_record);

					$transfer["order_id"]=$order["order_id"];
					$transfer["transfer_status"]=1;
					(new shopService())->orderEdit($transfer);

				}
        	}
        }
	}


}